package example.documentbased.editorModule.controller
{
	import example.documentbased.editorModule.models.EditorModuleModel;
	import example.documentbased.mainModule.models.vo.DocumentVO;
	
	import org.etherframework.controller.IReactiveCommand;
	import org.etherframework.controller.ReactiveCommand;
	
	import raix.reactive.IObservable;
	
	public class OpenDocumentCommand extends ReactiveCommand
	{
		private var _editorModel:EditorModuleModel;
		private var _document:DocumentVO;
		private var _editorController:IEditorController;
		
		public function OpenDocumentCommand(editorModel:EditorModuleModel,
											editorController:IEditorController)
		{
			_editorModel = editorModel;
			_editorController = editorController;
		}
		
		public function initialize(document:DocumentVO):IReactiveCommand
		{
			_document = document;
			markAsInitialized();
			
			return this;
		}
		
		override public function observable():IObservable
		{
			_editorModel.openDocument(_document);
			
			return _editorController.getSetCurrentDocumentCommand(_document).observable();
		}
	}
}